package com.qianli.cashmama.trade.repo.impl;

import com.qianli.cashmama.trade.common.enums.TradeStatusEnum;
import com.qianli.cashmama.trade.dao.TTradeFlowDao;
import com.qianli.cashmama.trade.domain.event.TradeFlow;
import com.qianli.cashmama.trade.entity.TTradeFlowEntity;
import com.qianli.cashmama.trade.repo.TradeFlowRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: sm
 * Date: 2017/7/31
 * Time: 下午11:46
 */
@Repository
public class TradeFlowRepositoryImpl implements TradeFlowRepository {

    @Autowired
    private TTradeFlowDao tTradeFlowDao;


    @Override
    public List<TradeFlow> queryListByTradeNo(String tradeNo) {
        List<TTradeFlowEntity> tradeFlowEntityList = tTradeFlowDao.getListByTradeNo(tradeNo);
        if (CollectionUtils.isEmpty(tradeFlowEntityList)) {
            return null;
        }
        List<TradeFlow> tradeFlowList = new ArrayList<>();
        for (TTradeFlowEntity flowEntity : tradeFlowEntityList) {
            tradeFlowList.add(new TradeFlow(flowEntity.getTradeNo(),
                    flowEntity.getAction(),
                    TradeStatusEnum.convertByStatus(flowEntity.getSourceStatus()),
                    TradeStatusEnum.convertByStatus(flowEntity.getTargetStatus()),
                    flowEntity.getOperatorDate()));
        }

        return tradeFlowList;
    }
}
